package com.tian.view.touch.dispatch

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import com.tian.view.databinding.FragmentMotionEventDispatchBinding

/**
 * @author tiansongtao
 * @date 2023/1/10 17:29
 *
 * android view 事件分发机制
 *
 * 函数：
 *  1. [View.dispatchTouchEvent] 分发 返回值表示是否消耗了该事件。
 *  2. [ViewGroup.onInterceptTouchEvent] 拦截
 *  3. [View.onTouchEvent] 消费
 *
 * dispatchTouchEvent分发： 分发触摸事件，事件传递给该view后，
 *  1. 该view为ViewGroup类型：
 *
 *
 */
class MotionEventDispatchFragment : Fragment() {


    private lateinit var b: FragmentMotionEventDispatchBinding

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        (requireActivity() as AppCompatActivity).supportActionBar?.title = "MotionEvent事件分发"
        b = FragmentMotionEventDispatchBinding.inflate(inflater)
        return b.root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        b.btNoConsume.setOnClickListener {
            b.cvChild.moveIntercept = false
        }
        b.btChildConsume.setOnClickListener {
            b.cvChild.moveIntercept = true
        }
        b.btParentConsume.setOnClickListener {
            b.clParent.moveIntercept = true
        }

    }
}